<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/include.inc.jsp" %>

<link rel="stylesheet" href="${ctx}/static/controls/zTree/css/zTreeStyle.css" type="text/css"/>
<form method="post" id="customesearchform${index}" action="${ctx}/customsearch/dialogsearch" style="min-height: 500px;">
    <div class="col-xs-12">
        <div class="mtrow">
            <div class="mtcolall">
                <c:forEach items="${listControl}" var="con">
                    <c:if test="${not empty con.controlName}">
                        <label class="mtlabel-auto">${con.controlName}：</label>
                        <c:choose>
                            <c:when test="${con.controlType == 0}">
                                <input type="text" class="mtinput" name="${con.fieldName}"
                                       controltype="${con.controlType}"
                                       value="${con.qcDefault}"/>
                            </c:when>
                            <c:when test="${con.controlType == 1}">
                                <input type="text" class="mtinput" name="${con.fieldName}"
                                       controltype="${con.controlType}"
                                       value="${con.qcDefault}"/>
                            </c:when>

                        </c:choose>
                    </c:if>
                </c:forEach>
                <c:if test="${fn:length(listControl) > 0}">
                    <a class="mtbtn search marginleft dialogsearch${index}" href="#"><i
                            class="mtfa mt-search"></i><span>查询</span></a>
                </c:if>
            </div>
        </div>
        <div>
            <ul id="menuTree${index}" class="ztree"></ul>
        </div>
    </div>
    <div class="defaultparam${index}" style="display: none;">${defaultParam}</div>
    <div class="getresultBtn${index}"></div>
    <input type="hidden" class="contentidHid${index}"/>
    <input type="hidden" class="resultHid${index}"/>
</form>
</body>
</html>
<script type="text/javascript" src="${ctx}/static/controls/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${ctx}/static/controls/zTree/js/jquery.ztree.excheck.js"></script>

<script type="text/javascript">
    $(function () {
        var zTree;
        var zNodes = ${data};
        var setting = {
            data: {
                key: {
                    name: "result2"
                },
                simpleData: {
                    enable: true,
                    idKey: "result1",
                    pIdKey: "result11"

                }
            },
            callback: {
                beforeClick: beforeClick
            }
        };

        zTree = $.fn.zTree.init($("#menuTree${index}"), setting, zNodes);
        zTree.expandAll(true);

        function beforeClick(treeId, treeNode) {
            if (treeNode.result1 <= 0) {
                layer.msg("该记录不能选择", {
                    icon: 3
                });
                return;
            }
            var result = {};
            result["result1"] = treeNode.result1;
            result["result2"] = treeNode.result2;
            result["result3"] = treeNode.result3;
            $(".resultHid${index}").val(JSON.stringify(result));

            $("#" + $(".contentidHid${index}").val()).parent().parent().find(".jconfirm-buttons .btn-blue").click();
            var check = (treeNode && !treeNode.isParent);
            return check;
        }


        $(".dialogsearch${index}").click(function () {

            $.ajax({
                type: "POST",
                url: "${ctx}/customsearch/dialogsearch",
                contentType: "application/json",
                data: JSON.stringify({
                    sqlmapId: "${sqlmapId}",
                    searchstringparam: $("#customesearchform${index} .mtcolall :input[controltype='0']").serializeArray(),
                    searchvalueparam: $("#customesearchform${index} .mtcolall :input[controltype='1']").serializeArray(),
                    defaultParam: JSON.parse($("#customesearchform${index} .defaultparam${index}").html())
                }),
                success: function (result) {
                    zNodes = JSON.parse(result);
                    zTree = $.fn.zTree.init($("#menuTree${index}"), setting, zNodes);
                }
            })
        });
    });

</script>
